// index.js
// 获取应用实例
const app = getApp()
const api = require('../../utils/util')
Page({
    // 页面分享
    onShareAppMessage () {},
    // 分享朋友圈
    onShareTimeline () {},
    data: {
        imagesUrl: app.globalData.imagesUrl,
        userName: '',
        companyName: '',
        headpic: '',
        company_id:'',
        is_count: false
     
    },
    onLoad(){
      
    },

    onShow(){
      let userinfo = app.globalData.userinfo;
       console.log(userinfo)
       if(!userinfo){
         wx.redirectTo({
           url: '/pages/login/login',
         })
       }
      let that = this;

      let param = {
        phone: app.globalData.userinfo.usermobile
      }
      api.get_userInfo(param).then(function(res){
          if(res.code == '1'){
           
          }else{
          
            wx.setStorageSync('userinfo', res.data)
            app.globalData.userinfo = res.data;

            that.setData({
              userName: app.globalData.userinfo.name,
              companyName: app.globalData.userinfo.companyName,
              headpic: app.globalData.siteUrl + app.globalData.userinfo.headpic,
              company_id: app.globalData.userinfo.company_id
          })
    

            wx.switchTab({
              url: '/pages/my/my',
            })
          }
      })


      
      this.memberSupply1_count(that)
    },

    updateInfo: function(){
       wx.navigateTo({
         url: '/pages/my/edit-user-info/edit-user-info',
       })
    },
    
    logout: function(){
       app.globalData.userinfo = '';
       wx.redirectTo({
         url: '/pages/login/login',
       })
    },

    memberSupply1_count: function(that){
  
      let param = {
        ucode: app.globalData.userinfo.ucode
      }
      api.memberSupply1_count(param).then(function(res){
          if(res.data == '1'){
            that.setData({
              is_count: true
            })
            wx.showTabBarRedDot({
              index: 3,
            });
          }else{
            that.setData({
              is_count: false
            })
            wx.hideTabBarRedDot({
              index: 3,
            })
          }
          console.log(res.data)
      })
    }

})
